import {computed} from "vue";
import {getToken} from "@/util/token";

export function formatDate(timeStr: string, formatType: string | undefined ): string {
    if (!timeStr) {
        return '';
    }
    const date = new Date(timeStr);
    if (isNaN(date.getTime())) {
        throw new Error(`Invalid date string: ${timeStr}`);
    }
    const padZero = (num: number): string => (num < 10 ? '0' + num : num.toString());
    const year = date.getFullYear();
    const month = padZero(date.getMonth() + 1);
    const day = padZero(date.getDate());
    const hours = padZero(date.getHours());
    const minutes = padZero(date.getMinutes());
    const seconds = padZero(date.getSeconds());
    if (!formatType){
        return `${year}-${month}-${day}`;
    }
    switch (formatType) {
        case 'MM/DD/YYYY':
            return `${month}/${day}/${year}`;
        case 'DD-MM-YYYY':
            return `${day}-${month}-${year}`;
        case 'HH:mm:ss':
            return `${hours}:${minutes}:${seconds}`;
        case 'YYYY-MM-DD HH:mm:ss':
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        case 'MM-DD-YYYY HH:mm:ss':
            return `${month}-${day}-${year} ${hours}:${minutes}:${seconds}`;
        case 'DD/MM/YYYY HH:mm:ss':
            return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`;
        default:
            return `${year}-${month}-${day}`;
    }
}
export const chunkUpload="/api/file/upload/chunk"
export const shareCoverUpload="/api/file/upload/share/video/cover"
export const chunkMerge="/api/file/upload/chunk/merge"
export const fileUpload="/api/file/upload/common"
export const getHeaders =()=>{
    return {
        "token": getToken(),
        "user-type":'admin'
    }
}
